The present invention concerns management of storage devices and pertains particularly to determining thresholds and wrap-around conditions in a first-in-first-out memory.
A first-in-first-out memory is a memory in which data is read out of the memory in the order in which the data is placed in the memory. FIFO memories are thus well suited for uses such as buffering data in a network controller.
When implementing a dual port memory as a circular first-in-first-out (FIFO) queue, a designer must choose a finite memory depth. When using the FIFO queue, firmware or software keeps track of a write address (a location where additional data is to be next written into the FIFO queue) and a read address (a location where data is to be next read from the FIFO queue). In addition certain conditions are also monitored. These conditions include, for example, whether the FIFO queue is full (i.e., no more data should be written into the FIFO queue before some data is read out of the FIFO queue), empty (i.e., no more data should be read out of the FIFO queue before more data is written into the FIFO queue), or a threshold has been crossed (e.g., a certain threshold of bytes have been written into the FIFO queue so that reads are allowed to be made out of the FIFO queue).
The full condition and the empty condition can determined by comparing the write address to the read address. However because the FIFO queue has a finite length, this introduces a certain complexity in the comparison. This is because any comparison must take into consideration that both the read address and the write address at times wrap around so as to return to the first address. This wrap around can be especially complex for an application in which it is required to determine whether a certain quantity of data is available to be read out of the FIFO queue.